package org.fixies.spreadsheet.excel;

import org.fixies.factory.GenericFactory;
import org.fixies.resource.BookLoader;
import org.fixies.resource.BookLoaderFactory;
import org.fixies.resource.ResourceLoader;
import org.fixies.spreadsheet.interpreter.BookContext;

public class XlsBookLoaderFactory implements BookLoaderFactory {

    private ResourceLoader resourceLoader_;

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        resourceLoader_ = resourceLoader;
    }

    private BookContext createBookContext() {
        return (BookContext) GenericFactory.getInstance("bookContext");
    }

    @Override
    public BookLoader createBookLoader(Class<?> klass, String name) {
        BookLoader loader = new XlsBookLoader(klass, name, createBookContext());
        loader.setResourceLoader(resourceLoader_);
        return loader;
    }

    @Override
    public BookLoader createBookLoader(Class<?> klass) {
        BookLoader loader = new XlsBookLoader(klass, createBookContext());
        loader.setResourceLoader(resourceLoader_);
        return loader;
    }
}
